package edu.whu;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.Properties;

public class Main {
    public static void main(String[] args) {
       work("Apple");
    }
    public static void work(String workname){
        try {
            // 读取文件
            Properties properties = new Properties();
            InputStream inputStream = Main.class.getClassLoader().getResourceAsStream("myapp.properties");
            properties.load(inputStream);

            // 获取类名
            String className = properties.getProperty(workname);

            // 创建对象
            Class<?> clazz = Class.forName(className);
            Object obj = clazz.newInstance();

            // 检查类的方法
            Method[] methods = clazz.getDeclaredMethods();

            for (Method method : methods) {
                // 调用带有注解的方法
                if (method.isAnnotationPresent(InitMethod.class)) {
                    method.invoke(obj);
                }

                //调用所有函数
                //method.invoke(obj);
            }
            inputStream.close();
        }
        catch (Exception e) {
            System.out.println("出现了异常！");;
        }
    }
}